import  React,{ createContext,useState,useEffect } from "react";
const AuthContext = createContext({});

const AuthProvider = ({children}:any)=>{
  const [state,setState] = useState<any>(null)

  useEffect(()=>{
    const loadLocalStorageDate =async()=>{
      let data:any = {};
      setState({...state,user:data?.user,token:data?.token});
    }
    loadLocalStorageDate();
  },[])

  const loginOut=async()=>{
    let data = {
      token:null,
      user:null
    }
    setState(data);
    // 退出登录
  }

  return (
    <AuthContext.Provider value={[state,setState,loginOut]}>
      {children}
    </AuthContext.Provider>
  )
}

export {AuthContext,AuthProvider};